#include "StdAfx.h"
#include "SubStructure.h"
#include "Mediator.h"
#include "Enemy.h"

Enemy::Enemy()
{
	processor = Mediator::Instance();
	move_count = 0;
	ani_count = 0;
	nowMoveState1 = 0;
	nowMoveState2 = 0;
	nowAniState1 = 0;
	nowAniState2 = 0;
	shoot_count = 0;
	live_time = 0;
}

Enemy::~Enemy()
{
	int i = 0;
	int j = 0;
	for(i = 0; i < _Ani.size() ; ++i)
	{
		for(j = 0; j < _Ani[i].size(); ++j)
		{
			if(_Ani[i][j] != NULL)
				delete _Ani[i][j];
		}
		_Ani[i].clear();
	}
	_Ani.clear();
	
	for(i = 0; i < _Move.size() ; ++i)
	{
		for(j = 0; j < _Move[i].size(); ++j)
		{
			if(_Move[i][j] != NULL)
				delete _Move[i][j];
		}

		_Move[i].clear();
	}
	_Move.clear();
}

void Enemy::Set_ani(AniVec2 nAni)
{
	_Ani = nAni;
	now_ani = *_Ani[nowAniState1][nowAniState2];
}

void Enemy::Set_pattern(EventList nlist)
{
	makePattern = nlist;
}

void Enemy::Set_Bound(BoundBoxVec nbound)
{
	bound = nbound;
}

BoundBoxVec Enemy::Get_Bound()
{
	return bound;
}

void Enemy::Set_move(Move_Vec2 nMove)
{
	_Move = nMove;
	now_move = *_Move[nowMoveState1][nowMoveState2];
}

void Enemy::Set_Pos(D3DXVECTOR2 npos)
{
	pos = npos;
}

void Enemy::Change_ani(DWORD nState)
{
	nowAniState1 = nState;
	nowAniState2 = 0;
	now_ani = *_Ani[nowAniState1][nowAniState2];
	ani_count = 0;
}

void Enemy::Set_life(DWORD nlife)
{
	life = nlife;
	nowlife = nlife;
}

void Enemy::Set_item(DWORD item, DWORD cherry)
{
	Pitem = item & 0x0000ffff;
	Titem = item>>16;
	Citem = cherry;
}

D3DXVECTOR2 Enemy::Get_CPos()
{
	return pos;
}

DWORD Enemy::Get_Pitem()
{
	return Pitem;
}

DWORD Enemy::Get_Titem()
{
	return Titem;
}

DWORD Enemy::Get_Citem()
{
	return Citem;
}

DWORD Enemy::Damaged(DWORD damage)
{
	if(nowlife < damage)
	{
		nowlife = 0;
	}
	else
	{
		nowlife -= damage;
	}
	return nowlife;
}